package presentation;

import java.awt.GridLayout;
import java.awt.Window;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;
import java.awt.dnd.DragSourceMotionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;

import solitaire.application.TasDeCartes;

import controleur.CCarte;
import controleur.CSabot;
import controleur.CTasDeCartes;
import controleur.CUsine;
import controleur.ICTasDeCartes;

public class PTasDeCartes extends JPanel implements IPTasDeCartes{

	private static final long serialVersionUID = 42;
	private ICTasDeCartes controleur;
	
	public PTasDeCartes(CTasDeCartes c){
		setControleur(c);
		this.setVisible(true);
		this.setLayout(null);
	}
	
	public ICTasDeCartes getControleur() {
		return controleur;
	}
	
	public void initialiser(){
		if(! ((TasDeCartes) controleur).isVide())
		{
			CTasDeCartes controleur_tmp = (CTasDeCartes) this.getControleur();
			for(int i = 1; i <= controleur_tmp.getNombre(); i++)
			{
				try {
					this.add((PCarte)((CCarte)controleur_tmp.getCarte(i)).getPresentation());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}

	public void setControleur(ICTasDeCartes controleur) {
		this.controleur = controleur;
	}
	
	public static void main(String[] args) throws Exception
	{
		CUsine monUsine = new CUsine();
		CTasDeCartes c = (CTasDeCartes) monUsine.newTasDeCartes("Mon Tas", monUsine);
		CCarte mc = new CCarte(1, 1);
		mc.setFaceVisible(true);
		c.empiler(mc);
		mc = new CCarte(1,2);
		c.empiler(mc);
		mc.setFaceVisible(true);
		mc = new CCarte(1,3);
		mc.setFaceVisible(true);
		c.empiler(mc);
		mc = new CCarte(1,4);
		mc.setFaceVisible(true);
		c.empiler(mc);
		PTasDeCartes p = (PTasDeCartes) c.getPresentation();
		p.setLayout(new GridLayout());
		p.setVisible(true);
		p.initialiser();
		JFrame f = new JFrame();
		f.setVisible(true);
		f.setBounds(100, 100, 0, 127);
		f.add(p);
	}

	
}